#!/bin/bash

# First modify the 'dset ...' in post_0p25/0p50/0p125.ctl for MCV output.
# Second set the resolution and figurename to be output in the NCL command parameters. The resolution is defined by Degree Of Freedom.

#======== model level    =======
#cdo -P 24 -f nc import_binary model.ctl tmp_divon_model.nc
#cdo -P 8 -selvar,u,v -sellevidx,15 -seltimestep,9 tmp_divon_model.nc output.nc

#======== pressure level =======
echo ' Convert to NetCDF from binary ...'
#cdo -P 24 -f nc import_binary post_0p25.ctl tmp.nc
echo ' Select u,v at specifed level and timestep ...'
#cdo -P 8 -selvar,u,v -sellevel,200 -seltimestep,2 tmp.nc output.nc
echo ' Calculate and plot kinetic energy spectrum using NCL ...'

figurename=MCV_2023060112_f00
resolution=0.25
ncl ../Scripts/calc_kinetic_energy_spectrum.ncl \
    resolution=$resolution \
    figname=\"${figurename}\"

echo ' Convert to png from ps format ...'
convert -trim -density 300 ${figurename}.ps ${figurename}.png

rm -fr tmp.nc ${figurename}.ps
